package com.ruoyi.business.service.impl;

import com.ruoyi.business.domain.Customer;
import com.ruoyi.business.mapper.CustomerMapper;
import com.ruoyi.business.service.ICustomerService;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

/**
 * 结算单Service业务层处理
 * 
 * @author wolfcode
 * @date 2021-05-17
 */
@Service
public class CustomerServiceImpl implements ICustomerService
{
    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 查询结算单
     * 
     * @param id 结算单ID
     * @return 结算单
     */
    @Override
    public Customer selectCustomerById(Long id)
    {
        return customerMapper.selectCustomerById(id);
    }

    /**
     * 查询结算单列表
     * 
     * @param customer 结算单
     * @return 结算单
     */
    @Override
    public List<Customer> selectCustomerList(Customer customer)
    {
        return customerMapper.selectCustomerList(customer);
    }

    /**
     * 新增结算单
     * 
     * @param customer 结算单
     * @return 结果
     */
    @Override
    public int insertCustomer(Customer customer)
    {
        customer.setCreateTime(DateUtils.getNowDate());
        return customerMapper.insertCustomer(customer);
    }

    /**
     * 修改结算单
     * 
     * @param customer 结算单
     * @return 结果
     */
    @Override
    public int updateCustomer(Customer customer)
    {
        return customerMapper.updateCustomer(customer);
    }

    /**
     * 删除结算单对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteCustomerByIds(String ids)
    {
        return customerMapper.deleteCustomerByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除结算单信息
     * 
     * @param id 结算单ID
     * @return 结果
     */
    @Override
    public int deleteCustomerById(Long id)
    {
        return customerMapper.deleteCustomerById(id);
    }
    /**
     * 更新结算单的金额
     * @param customerId 结算单ID
     * @param totalAmount 消费总金额
     * @param totalQuantity 消费服务项个数
     * @param discountAmount 总优惠基恩
     */
    @Override
    public int updateAmount(Long customerId, BigDecimal totalAmount, BigDecimal totalQuantity, BigDecimal discountAmount) {
        return customerMapper.updateAmount(customerId,totalAmount,totalQuantity,discountAmount);
    }

    @Override
    public int delete(Long id) {
        return customerMapper.deleteCustomerById(id);
    }

    /**
     * 根据预约单信息查询结算单ID
     * @param mainteenanceId
     * @return
     */
    @Override
    public Long selectCustomerByMainteenanceId(Long mainteenanceId) {
        return customerMapper.selectCustomerByMainteenanceId(mainteenanceId);
    }
}
